using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
using System.IO;
using System.Security.Cryptography; 

/// <summary>
/// Summary description for clsCon
/// </summary>
/// 

namespace Bestlife.ERP.DataAccess
{

    public class clsCon:System.Web.UI.Page
    {
       
        public static SqlConnection conn_new = new SqlConnection();

        //-----check user login email
        public static bool Uloged = false;
        //public static string UserName = "";

        //-----Session Check Variable--
        public static bool SChk = false;


     
        
        public static SqlConnection connect(string strConStr)
        {
            try
            {


                if (conn_new.State != System.Data.ConnectionState.Open)
                {
                    conn_new.ConnectionString = strConStr;
                    conn_new.Open();
                }
                else
                {
                    return null;
                }
               

            }

            catch
            {
               

            }
            return conn_new;
        }

        public static SqlDataReader ReadTable(string strReadStr)
        { 
              
                SqlCommand COMMA = new SqlCommand(strReadStr, conn_new);
                SqlDataReader rdNew;
                rdNew = COMMA.ExecuteReader();
                return rdNew;
                
                        
        }

        public static Boolean AddEditDel(string strAddEditDel)
        {
            SqlCommand ADDCOM = new SqlCommand(strAddEditDel, conn_new);
            int a;
            a = ADDCOM.ExecuteNonQuery();
            if (a == 0)
                return false;
            else
                return true;


        }
        public static void setDropDownList(DropDownList sDropDownList, string sSQL)
        {
            SqlDataReader rdA;
            rdA = ReadTable(sSQL);
            sDropDownList.Items.Clear();

            while (rdA.Read())
            {
                for (int i = 0; i < 1; i++)
                    sDropDownList.Items.Insert(i, (rdA[0].ToString()));
            }

            rdA.Close();
        }

        public static void GenCode(TextBox sTextBox, string sSQL)
        {
            SqlDataReader rdSetNo;
            rdSetNo = clsCon.ReadTable(sSQL);

            if (rdSetNo.HasRows)
            {
                rdSetNo.Read();

                int xx = int.Parse(rdSetNo[0].ToString());
                xx = xx + 1;
                sTextBox.Text = Convert.ToString(xx);
            }
            else
            {
                sTextBox.Text = "1";
            }
            rdSetNo.Close();
        }
    }
}


